package com.helpustotravel.model.jdo;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.Text;

@PersistenceCapable
public class Traveller {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent
    private String name;
    
    @Persistent
    private String completeName;
    
    @Persistent
    private String type;
    
    @Persistent
    private Text story;
    
    //@Persistent(mappedBy = "traveller")
    //@Element(dependent = "true")
    //@Order(extensions = @Extension(vendorName="datanucleus",key="list-ordering", value="date asc"))
    
    @Persistent
    private List<Long> positionIds;
    
    public Traveller() {
    	this.name = "";
    	this.completeName = "";
    	this.type = "";
    	this.story = new Text("");
    	this.positionIds = null;
    }

	public Key getKey() {
		return key;
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCompleteName() {
		return completeName;
	}

	public void setCompleteName(String completeName) {
		this.completeName = completeName;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getStory() {
		return story.getValue();
	}

	public void setStory(String story) {
		this.story = new Text(story);
	}

	public List<Long> getPositionIds() {
		return positionIds;
	}

	public void setPositionIds(List<Long> positionIds) {
		this.positionIds = positionIds;
	}

	public void addPosition(long positionId) {
		if(positionIds == null) {
			positionIds = new ArrayList<Long>();
		}
		
		positionIds.add(positionId);
	}
    
}
